#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<queue>

using namespace std;


struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

class Solution {
public:
    vector<double> averageOfLevels(TreeNode* root) {
        queue<TreeNode*> q;
        TreeNode* cur = root;
        q.push(cur);
        vector<double> ret;
        while (!q.empty())
        {
            int n = q.size();
            int m = n;
            double sum = 0;
            while (n--)
            {
                cur = q.front();
                q.pop();
                sum += cur->val;
                if (cur->left != nullptr)
                {
                    q.push(cur->left);
                }
                if (cur->right != nullptr)
                {
                    q.push(cur->right);
                }
            }

            double k = sum / m;
            ret.push_back(k);
        }
        return ret;
    }



    void Inorder(vector<int>& v, TreeNode* root)
    {
        if (root == nullptr)
        {
            return;
        }

        if (root->left != nullptr)
        {
            Inorder(v, root->left);
        }

        v.push_back(root->val);

        if (root->right != nullptr)
        {
            Inorder(v, root->right);
        }
    }

    int getMinimumDifference(TreeNode* root) {
        vector<int> v;
        Inorder(v, root);

        int n = v.size();
        int ans = v[n - 1] - v[0];
        for (int i = 1; i < n; i++)
        {
            ans = min(ans, v[i] - v[i - 1]);
        }
        return ans;
    }
};

int main()
{
    Solution S;
    return 0;
}